<?php

namespace App\Repositories;

use App\Models\DeveloperTestingRel;
use Cache;

class DeveloperTestingRelRepository extends Repository
{
    static $tag = 'developer.testing.rel';

    static $tableName = 'developer_testing_rel';


    public function getTestingListByUnionCode($unionCode)
    {

        $cacheKey = getCacheKey('testing.cache_key.developer_testing_rel.list').$unionCode;
        $value = $this->remember($cacheKey, function () use ($unionCode) {
            return DeveloperTestingRel::where('union_code', $unionCode)->get();
        });
        return $value;
    }


    public function getByTidUnionCode($unionCode,$tid){
        $cacheKey = getCacheKey('testing.cache_key.developer_testing_rel.list').'_'.$tid.'_'.$unionCode;
        $value = $this->remember($cacheKey, function () use ($tid,$unionCode) {
            return DeveloperTestingRel::where('union_code', $unionCode)->where('tid',$tid)->get();
        });
        return $value;
    }


    public function store($data)
    {
        $this->clearCache($this->tag());
        $res = DeveloperTestingRel::firstOrCreate($data);
        return $res;
    }

    public function batchInsertData($data){
        DeveloperTestingRel::batchInsertData(self::$tableName,$data);
    }





    public function cacheTime()
    {
        return config('testing.common_cache_time');
    }


    public function model()
    {
        return app(DeveloperTestingRel::class);
    }

    public function tag()
    {
        return self::$tag;
    }
}